define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {

	$scope.menu = {};



		if(params.father_id!='undefined'){
			httpService.post(app.urls.menu_select,{"id":params.father_id},function(data){
				if("0000" === data.code){
					$scope.menu_name = data.data[0].name;
					$scope.findButton(data.data[0].id);
				}else{
					alert(data.msg);
				}
			});
		}else {
			$scope.form.type=params.type;
		}

		$scope.findButton=function(menu_id){
			httpService.post(app.urls.button_select,{"menu_id":menu_id},function(data){
				if("0000" === data.code){
					$scope.buttons = data.data;
				}else{
					alert(data.msg);
				}
			});
		}

		//按钮事件
		$scope.operate = function(event) {
			$scope[event]();
		}


		//学年学期
		httpService.post(app.urls.prop_select,{},function(data){
			if("0000" === data.code){
				$scope.propList = data.data;
			}else{
				alert(data.msg);
			}
		});

		//查询学生列表
		$scope.find = function(){
			httpService.postpage(app.urls.gradlist_selectAll,$scope.form,function(data){
				if("0000" === data.code){
					$scope.rows = data.data;
				}else{
					alert(data.msg);
				}
			});
		}


		$scope.add = function (){

			eventBusService.publish("modal.page", "modules/content/schoolroll/gradlist/add?fk_menuid="+params.fk_menuid+ "&father_id=" + params.father_id);

			if(params.father_id!='undefined'){
				eventBusService.publish("modules.welcome.load", $scope.menu);
			}else {
				eventBusService.publish("modules.content.load", $scope.menu);
			}
		}



		//编辑
		$scope.pass = function() {
			var values = [];
			$('input[name="dataPk"]:checked').each(function() {
				values.push($(this).val());
			});

			if(values.length < 1) {
				eventBusService.publish("modal.alert", {"content":"请选择一条数据。"});
			}else{

				for(var i=0;i<values.length;i++){
					httpService.post(app.urls.gradlist_pass,{"id":values[i]}, function(data) {
						if(data.code=="0000"){
							eventBusService.publish("modal.alert", {"content": "通过成功"});
							eventBusService.publish("content.page.reload", data.data);
							eventBusService.publish("modal.page.close", {});
						}
					});
				}
			}
		}


		//编辑
		$scope.nopass = function() {
			var values = [];
			$('input[name="dataPk"]:checked').each(function() {
				values.push($(this).val());
			});

			if(values.length < 1) {
				eventBusService.publish("modal.alert", {"content":"请选择一条数据。"});
			}else{

				for(var i=0;i<values.length;i++){
					httpService.post(app.urls.gradlist_nopass,{"id":values[i]}, function(data) {
						if(data.code=="0000"){
							eventBusService.publish("modal.alert", {"content": "拒绝通过"});
							eventBusService.publish("content.page.reload", data.data);
							eventBusService.publish("modal.page.close", {});
						}
					});
				}
			}
		}


		//编辑
		$scope.confirm = function() {
			var values = [];
			$('input[name="dataPk"]:checked').each(function() {
				values.push($(this).val());
			});

			if(values.length < 1) {
				eventBusService.publish("modal.alert", {"content":"请选择一条数据。"});
			}else{

				for(var i=0;i<values.length;i++){
					httpService.post(app.urls.gradlist_confirm,{"id":values[i]}, function(data) {
						if(data.code=="0000"){
							eventBusService.publish("modal.alert", {"content": "确认成功"});
							eventBusService.publish("content.page.reload", data.data);
							eventBusService.publish("modal.page.close", {});
						}
					});
				}
			}
		}


		//编辑
		$scope.noconfirm = function() {
			var values = [];
			$('input[name="dataPk"]:checked').each(function() {
				values.push($(this).val());
			});

			if(values.length < 1) {
				eventBusService.publish("modal.alert", {"content":"请选择一条数据。"});
			}else{

				for(var i=0;i<values.length;i++){
					httpService.post(app.urls.gradlist_noconfirm,{"id":values[i]}, function(data) {
						if(data.code=="0000"){
							eventBusService.publish("modal.alert", {"content": "拒绝确认"});
							eventBusService.publish("content.page.reload", data.data);
							eventBusService.publish("modal.page.close", {});
						}
					});
				}
			}
		}

		//编辑
		$scope.leavepass = function() {
			var values = [];
			$('input[name="dataPk"]:checked').each(function() {
				values.push($(this).val());
			});

			if(values.length < 1) {
				eventBusService.publish("modal.alert", {"content":"请选择一条数据。"});
			}else{

				for(var i=0;i<values.length;i++){
					httpService.post(app.urls.gradlist_leavenopass,{"id":values[i]}, function(data) {
						if(data.code=="0000"){
							eventBusService.publish("modal.alert", {"content": "离校确认确认成功"});
							eventBusService.publish("content.page.reload", data.data);
							eventBusService.publish("modal.page.close", {});
						}
					});
				}
			}
		}


		//按钮点击事件-条件查询
		$scope.select = function(){
			$scope.page.current = 1;
			$scope.find();
		}

		//接收数据刷新
		eventBusService.subscribe('content.page.reload', function(event,data) {
			$scope.find();
		});


		let init = function (){
			$scope.form.fk_unit=app.userInfo.unitId;
			$scope.find();
		}


		init();
		//选择数据
		$scope.optData = function (element) {
			if($(element).find("input[name='dataPk']").is(":checked")){
				$(element).find("input[name='dataPk']").prop("checked",false);
				$(element).removeClass("opt_tr");
			}else{
				$(element).find("input[name='dataPk']").prop("checked",true);
				$(element).addClass("opt_tr");
			}
		}
		$scope.checkAll = function(target) {
			$("#" + $scope.controllerName + " input[name='dataPk']").each(function() {
				if ($(this).prop("checked")) {
					$(this).prop('checked', false);
					$(this).parents("tr").removeClass("opt_tr");
				} else {
					$(this).prop('checked', true);
					$(this).parents("tr").addClass("opt_tr");
				}
			})
		}
}}});